package com.tuananh.radnom.model.iputils;

import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import com.tuananh.radnom.model.netservice.MyMapTypeAdapter;
import com.tuananh.radnom.model.utils.IPUtils;

@XmlRootElement
public class IPRange {
	ArrayList<IPFilter> includeIps;
	ArrayList<IPFilter> excludeIps;
	/**
	 * List of parameter
	 */
	HashMap<String, String> params = new HashMap<String, String>();

	@XmlJavaTypeAdapter(MyMapTypeAdapter.class)
	@XmlElement(required=false)
	public HashMap<String, String> getParams() {
		if (params == null)
			params = new HashMap<String, String>();
		return params;
	}

	public void setParams(HashMap<String, String> params) {
		this.params = params;
	}

	@XmlElement(name = "include")
	public ArrayList<IPFilter> getIncludeIps() {
		return includeIps;
	}

	public void setIncludeIps(ArrayList<IPFilter> includeIps) {
		this.includeIps = includeIps;
	}

	@XmlElement(name = "exclude")
	public ArrayList<IPFilter> getExcludeIps() {
		return excludeIps;
	}

	public void setExcludeIps(ArrayList<IPFilter> excludeIps) {
		this.excludeIps = excludeIps;
	}
	public HashMap<String, String> getParamByIp(String ip){
		if (IPUtils.inRange(this, ip))
			return this.params;
		return null;
	}
}
